/**
 * @file   PA_E.cpp
 * @author ZL <zuoling@Black>
 * @date   Fri Oct  7 01:14:06 2022
 * 
 * @brief  1.8.2 PA_E
 * 
 * 
 */

#include "EquationSolver.h"

const double V = 12.4, L = 10, r = 1;/// define const given by topic

/** 
 * 
 * 
 * 
 * @return Create the function class in Topic E
 */
class F : public Function
{
public:
    double operator ()(double _x)
	{
	    double x = _x;
	    double y;
	    y = L*(0.5*pi*r*r-r*r*asin(x/r)-x*sqrt(r*r-x*x))-V;
	    return y;
	};
    double diff(double _x)
	{
	    double x = _x;
	    double y;
	    y = L*(-r*1.0/sqrt(1.0-(x*x)/(r*r))-sqrt(r*r-x*x)+x*x/sqrt(r*r-x*x));
	    return y;
	}
};

int main(int argc, char* argv[])
{
    F f;
    Bisection b(0, 1, 0.01, 200, f);
    Newton n(0.5, 0.01, 200, f);
    Secant s(0, 1, 0.01, 200, f);
    double y1 = b.solve();
    double y2 = n.solve();
    double y3 = s.solve();

    std::cout << "Bisection method, h1 = " << y1 << ", the depth is " << r-y1 << std::endl;
    std::cout << "Newton method, h2 = " << y2 << ", the depth is " << r-y2 << std::endl;
    std::cout << "Secant method, h3 = " << y3 << ", the depth is " << r-y3 << std::endl;
    return 0;
};
